home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / TCPTIMER.C < prev    next >
C/C++ Source or Header  |  1988-07-28  |  1KB  |  60 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. /* Timer timeout */
  11. void
  12. tcp_timeout(arg)
  13. char *arg;
  14. {
  15.     register struct tcb *tcb;
  16.  
  17.     tcb = (struct tcb *)arg;
  18.  
  19.     if(tcb == NULLTCB)
  20.         return;
  21.  
  22.     /* Make sure the timer has stopped (we might have been kicked) */
  23.     stop_timer(&tcb->timer);
  24.  
  25.     switch(tcb->state){
  26.     case TIME_WAIT:        /* 2MSL timer has expired */
  27.         close_self(tcb,NORMAL);
  28.         break;
  29.     default:        /* Retransmission timer has expired */
  30.         tcb->flags |= RETRAN;    /* Indicate > 1  transmission */
  31.         /* Perform backoff calculation */
  32.         tcb->backoff++;
  33.         tcb->timer.start = BETA * backoff(tcb->backoff)
  34.          * max(tcb->srtt,1) / MSPTICK;
  35. #ifdef    notdef
  36.         tcb->timer.start = backoff(tcb->backoff)
  37.             * (BETA * tcb->srtt)/MSPTICK; 
  38.         /* Never initialize the timer with zero; it won't run! */
  39.         tcb->timer.start = max(tcb->timer.start,1);
  40. #endif
  41.         tcb->snd.ptr = tcb->snd.una;
  42.         tcp_output(tcb);
  43.     }
  44. }
  45. /* Backoff function - the subject of much research */
  46. backoff(n)
  47. int n;
  48. {
  49.     /* Use binary exponential up to retry #4, and quadratic after that
  50.      * This yields the sequence
  51.      * 1, 2, 4, 8, 16, 25, 36, 49, 64, 81, 100 ...
  52.      */
  53.  
  54.     if(n <= 4)
  55.         return 1 << n;    /* Binary exponential back off */
  56.     else
  57.         return n * n;    /* Quadratic back off */
  58. }
  59.  
  60.